package com.api.shopapi.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.api.shopapi.entity.MyResult;
import com.api.shopapi.entity.Staff;
import com.api.shopapi.service.StaffService;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("VisualAccount")
public class VisualAccountController extends BaseController {


    @Autowired
    @Qualifier("StaffServiceImplOne")
    private StaffService staffService;

    @RequestMapping(value = "Login",method = RequestMethod.POST)
    public MyResult Login(@RequestBody JSONObject jsonObject){

        try {

            String loginName = jsonObject.getString("loginName");
            String staffCode = jsonObject.getString("staffCode");

            Staff staff = staffService.getByStaffCode(staffCode);


            JSONObject jsonObject1=new JSONObject();

            JSONObject visualAccount = new JSONObject();
            visualAccount.put("loginName",loginName);
            visualAccount.put("password","");
            visualAccount.put("visualAccountCode","");
            jsonObject1.put("visualAccount",visualAccount);

            jsonObject1.put("staffCode",staffCode);

            JSONArray visualAccountShopGovernmentCodeList = new JSONArray();
            visualAccountShopGovernmentCodeList.add(staff.getGovernmentCode());
            jsonObject1.put("visualAccountShopGovernmentCodeList",visualAccountShopGovernmentCodeList);

            return success(jsonObject1);
        } catch (Exception e) {
            insertError("/VisualAccount/Login",jsonObject.toJSONString(),getExceptionMsg(e),"api");
            return anomalous(getExceptionMsg(e));
        }
    }


}
